package com.program.cloudmanage.tripteam.controller;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.program.cloudmanage.tripteam.domain.Car;
import com.program.cloudmanage.tripteam.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RefreshScope
@RequestMapping("/Car")
public class CarController {
    @NacosInjected
    @Autowired
    private CarService carService;

    @GetMapping("/Car")
    public List<Car> showCars(){
        return carService.showCars();
    }

    @GetMapping("/test")
    public String test(){
        return "hello world";
    }

    @PostMapping("/searchCar")
    public Car searchCar(@RequestBody Car car){
        return carService.searchCar(car.getCarid());
    }
    @PostMapping("/searchCarByTeamId")
    public List<Car> searchCarByTeamId(@RequestBody Car car){
        return carService.searchCarByTeamId(car.getTeamid());
    }
    @PostMapping("/searchCarByPersonId")
    public Car searchCarByPersonId(@RequestBody Car car){
        return carService.searchCarByPersonId(car.getPersonid());
    }

    @PostMapping("/insertCar")
    public String insertCar(@RequestBody Car car){
        carService.insertCar(car);
        return "OK";
    }

    @PostMapping ("/deleteCar")
    public String deleteCar(@RequestBody Car car){
        carService.deleteCar(car.getCarid());
        return "OK";
    }

    @PostMapping("/updateCar")
    public String updateCar(@RequestBody Car car) {
        carService.updateCar(car);
        return "OK";
    }


}